<?php

	// TITLE: Auction_item AUTO MODEL
	// FILE: scaffolding/model/auction_item.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createAuctionItem = function($con, $auctionItem) {
		$sql = 'INSERT INTO auction_item (id, auction_id, item_num, title, description, value, price, buyer_id, donation_id) VALUES (';
		$sql .= $auction_item->getId() . ', ';
		$sql .= $auction_item->getAuctionId() . ', ';
		$sql .= $auction_item->getItemNum() . ', ';
		$sql .= $auction_item->getTitle() . ', ';
		$sql .= $auction_item->getDescription() . ', ';
		$sql .= $auction_item->getValue() . ', ';
		$sql .= $auction_item->getPrice() . ', ';
		$sql .= $auction_item->getBuyerId() . ', ';
		$sql .= $auction_item->getDonationId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readAuctionItem = function($con, $id) {
		$sql = 'SELECT * FROM auction_item WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$auctionItem = new AuctionItem();
			$auctionItem->setId(result[0]);
			$auctionItem->setAuctionId($dbio->select($readAuction(result[1])));
			$auctionItem->setItemNum(result[2]);
			$auctionItem->setTitle(result[3]);
			$auctionItem->setDescription(result[4]);
			$auctionItem->setValue(result[5]);
			$auctionItem->setPrice(result[6]);
			$auctionItem->setBuyerId($dbio->select($readBuyer(result[7])));
			$auctionItem->setDonationId($dbio->select($readDonation(result[8])));
		} else {
			$auctionItem = false;
		}
		return $auctionItem;
	};

	$updateAuctionItem = function($con, $auctionItem) {
		$sql = 'UPDATE auction_item SET ';
		$sql .= 'id = ' . $auction_item->getId() . ', ';
		$sql .= 'auction_id = ' . $auction_item->getAuctionId() . ', ';
		$sql .= 'item_num = ' . $auction_item->getItemNum() . ', ';
		$sql .= 'title = ' . $auction_item->getTitle() . ', ';
		$sql .= 'description = ' . $auction_item->getDescription() . ', ';
		$sql .= 'value = ' . $auction_item->getValue() . ', ';
		$sql .= 'price = ' . $auction_item->getPrice() . ', ';
		$sql .= 'buyer_id = ' . $auction_item->getBuyerId() . ', ';
		$sql .= 'donation_id = ' . $auction_item->getDonationId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteAuctionItem = function($con, $id) {
		$sql = 'DELETE FROM auction_item WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listAuctionItem = function($con) {
		$sql = 'SELECT * FROM auction_item';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$auctionItems = array();
			while ($result = mysqli_fetch_array($results)) {
				$auctionItem = new AuctionItem();
				$auctionItem->setId(result[0]);
				$auctionItem->setAuctionId($dbio->select($readAuction(result[1])));
				$auctionItem->setItemNum(result[2]);
				$auctionItem->setTitle(result[3]);
				$auctionItem->setDescription(result[4]);
				$auctionItem->setValue(result[5]);
				$auctionItem->setPrice(result[6]);
				$auctionItem->setBuyerId($dbio->select($readBuyer(result[7])));
				$auctionItem->setDonationId($dbio->select($readDonation(result[8])));
				$auctionItems[] = auctionItem;
			}// end while
		} else {
			$auctionItems = false;
		}
		return $auctionItems;
	};

